def resolve_candidates(boxes, point):
    """
    Get the best box for a point, among the candidates, based
    un distance.
    This is something written hastly given that it's only
    run once for the whole script.
    Box to point matching is done with a rtree during the actual loop.
    :param boxes:
    :param point:
    :return:
    """
    if len(boxes) > 1:
        # look for box with the minimum centre
        mindist = 1e10
        minbox = None
        for i, box in enumerate(boxes):
            x, y, w, h, _ = box
            dist = ((x + w / 2) - point[0]) ** 2 + ((x + y / 2) - point[1]) ** 2
            if dist < mindist:
                mindist = dist
                minbox = box
        return minbox
    # return the only box
    return boxes[0]