def tracking_pts_sort_cmp(msg_x, msg_y):
    """
    Comparison function for sorting the the tracking pts messages. Used for sorting
    the based on ROI arean and distance. 
    """
    roi_x = msg_x.data.roi_src
    roi_y = msg_y.data.roi_src
    area_roi_x = roi_x[2]*roi_x[3]
    area_roi_y = roi_y[2]*roi_y[3]
    if area_roi_x < area_roi_y:
        return 1
    elif area_roi_x > area_roi_y:
        return -1
    else:
        dist_x = msg_x.data.distance
        dist_y = msg_y.data.distance
        if dist_x > dist_y:
            return 1
        elif dist_y > dist_x:
            return -1
        else:
            return 0