code: def distance_rule_match(
      end2end_indexes, end2end_bboxes, master_indexes, master_bboxes
  ):
      """
      Get matching between no-match end2end bboxes and no-match master bboxes.
      Use min distance to match.
      This rule will only run (no-match end2end nums > 0) and (no-match master nums > 0)
      It will Return master_bboxes_nums match-pairs.
      :param end2end_indexes:
      :param end2end_bboxes:
      :param master_indexes:
      :param master_bboxes:
      :return: match_pairs list, e.g. [[0,1], [1,2], ...]
      """
      min_match_list = []
      for j, master_bbox in zip(master_indexes, master_bboxes):
          min_distance = np.inf
          min_match = [0, 0]  # i, j
          for i, end2end_bbox in zip(end2end_indexes, end2end_bboxes):
              x_end2end, y_end2end = end2end_bbox[0], end2end_bbox[1]
              x_master, y_master = master_bbox[0], master_bbox[1]
              end2end_point = (x_end2end, y_end2end)
              master_point = (x_master, y_master)
              dist = cal_distance(master_point, end2end_point)
              if dist < min_distance:
                  min_match[0], min_match[1] = i, j
                  min_distance = dist
          min_match_list.append(min_match)
      return min_match_list
  
imports: import os
  import re
  import cv2
  import glob
  import copy
  import math
  import pickle
  import numpy
  from shapely.geometry import Polygon, MultiPoint
label_desc: Use image node_id 17 for calling a global function with example usage: distance_rule_match(end2end_indexes, end2end_bboxes, master_indexes, master_bboxes) and returns: min_match_list