def _filter_distance(barcodes, candidate, min_dist, distance):
    """Test whether {candidate} can be added to {barcodes} based on the minimum
    distance between {candidate} and all barcodes in {barcodes}.

    :arg list barcodes: List of barcodes.
    :arg str candidate: Candidate barcode.
    :arg int min_dist: Minimum distance between the barcodes.
    :arg function distance: Distance function.

    :returns bool: True if the barcode is clean, False otherwise.
    """
    for i in barcodes:
        if distance(i, candidate) < min_dist:
            return False

    return True