def update_preds_and_labels(pred, labels_matched, image_id, detected_labels, preds, labels, image_ids):
    """
    Convert the matched labels of the prediction bbox to binary label and update all predictions and labels
    Args:
        pred: Current prediction score
        labels_matched: GT labels for which the current prediction is a match
        image_id: Current image ID
        detected_labels: GT labels that have been detected so far for this image_id
        preds: List of all predictions, passed by reference
        labels: List of all binary labels, passed by reference
        image_ids: List of all image IDs, passed by reference

    Returns:
        detected_labels: GT labels that have been detected so far for this image_id
    """
    num_detected_so_far = len(detected_labels)
    detected_labels = detected_labels.union(set(labels_matched))

    # If the current prediction contribute to a new match, set label to 1
    if len(detected_labels) > num_detected_so_far:
        label = 1
        for _ in range(len(detected_labels) - num_detected_so_far):
            preds.append(float(pred))
            labels.append(float(label))
            image_ids.append(image_id)
    else:
        label = 0
        preds.append(float(pred))
        labels.append(float(label))
        image_ids.append(image_id)

    return detected_labels