def check_error(segments, max_error):
    """
    Checks the error (average distance between the points and
    the fitted line) of the segments.

    Parameters
    ----------
    segments : list of segments
        The wall segments to check.
    max_error : int or float
        The error at which a segments will be classified as invalid.

    Returns
    -------
    invalid_segments : list of int
        The indices of the segments which have a higher error than
        the given max error.
    """
    invalid_segments = []
    for i, s in enumerate(segments):
        error = s.residuals()
        if error > max_error:
            invalid_segments.append(i)
    return invalid_segments