def aai_thresholds(seq1, seq2, max_mismatches, min_matches):
    """Calculate AAI between sequences.

    Mismatches are only calculate across
    positions where both sequences have
    an amino acid. The max_mismatches
    threshold is used to quickly stop
    comparisons between divergent
    sequences.

    Parameters
    ----------
    seq1 : str
        First sequence.
    seq2 : float
        Second sequence.
    max_mismatches : int
        Maximum allowed mismatches between sequences.
    min_matches : int
        Minimum required matches between sequences.

    Returns
    -------
    float
        AAI between sequences, or 0 if criteria is not meet.
    """
    mismatches = 0
    matches = 0
    for c1, c2 in zip(seq1, seq2):
        if c1 == '-' or c2 == '-':
            continue
        elif c1 != c2:
            mismatches += 1
            if mismatches > max_mismatches:
                return 0
        else:
            matches += 1
    if matches < min_matches:
        return 0
    aai = float(matches) / (matches + mismatches)
    return aai
