def match_keypoints(optical_flow, prev_kps):
    """Match optical flow keypoints

    :param optical_flow: output of cv2.calcOpticalFlowPyrLK
    :param prev_kps: keypoints that were passed to cv2.calcOpticalFlowPyrLK to create optical_flow
    :return: tuple of (cur_matched_kp, prev_matched_kp)
    """
    cur_kps, status, err = optical_flow
    prev_matched_kp = []
    cur_matched_kp = []
    if status is None:
        return cur_matched_kp, prev_matched_kp
    for i, matched in enumerate(status):
        if matched:
            prev_matched_kp.append(prev_kps[i])
            cur_matched_kp.append(cur_kps[i])
    return cur_matched_kp, prev_matched_kp
