def match_detection_to_annotations(detection, annotations, overlap_threshold, overlap_fn):
    """ Compute the best match (largest overlap area) between a given detection and a list of annotations.

    Args:
        detection (brambox.boxes.detections.Detection): Detection to match
        annotations (list): Annotations to search for the best match
        overlap_threshold (Number): Minimum overlap threshold to consider detection and annotation as matched
        overlap_fn (function): Overlap area calculation function
    """
    best_overlap = overlap_threshold
    best_annotation = None
    for i, annotation in enumerate(annotations):
        if annotation.class_label != detection.class_label:
            continue

        overlap = overlap_fn(annotation, detection)
        if overlap < best_overlap:
            continue
        best_overlap = overlap
        best_annotation = i

    return best_annotation