code: def filter_matches(
      matcher_output: List[Tuple[int, int, int]], doc: Doc
  ) -> List[Tuple[Span, Span]]:
      # Filter into two cases:
      # 1. <Short Form> ( <Long Form> )
      # 2. <Long Form> (<Short Form>) [this case is most common].
      candidates = []
      for match in matcher_output:
          start = match[1]
          end = match[2]
          # Ignore spans with more than 8 words in them, and spans at the start of the doc
          if end - start > 8 or start == 1:
              continue
          if end - start > 3:
              # Long form is inside the parens.
              # Take one word before.
              short_form_candidate = doc[start - 2 : start - 1]
              long_form_candidate = doc[start:end]
  
              # make sure any parentheses inside long form are balanced
              if span_contains_unbalanced_parentheses(
                  long_form_candidate
              ):
                  continue
          else:
              # Normal case.
              # Short form is inside the parens.
              short_form_candidate = doc[start:end]
  
              # Sum character lengths of contents of parens.
              abbreviation_length = sum(
                  [len(x) for x in short_form_candidate]
              )
              max_words = min(
                  abbreviation_length + 5, abbreviation_length * 2
              )
              # Look up to max_words backwards
              long_form_candidate = doc[
                  max(start - max_words - 1, 0) : start - 1
              ]
  
          # add candidate to candidates if candidates pass filters
          if short_form_filter(short_form_candidate):
              candidates.append(
                  (long_form_candidate, short_form_candidate)
              )
  
      return candidates
  
file_path: scispacy/scispacy/abbreviation.py
imports: from typing import Tuple, List, Optional, Set, Dict
  from collections import defaultdict
  from spacy.tokens import Span, Doc
  from spacy.matcher import Matcher
  from spacy.language import Language
label_desc: Use image node_id 3 for calling a global function with example usage: filter_matches(matcher_output, doc) and returns: candidates