<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def query_schema(query_params_schema, min_version=None, max_version=None):
 """Register a schema to validate request query parameters."""


    def add_validator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            if 'req' in kwargs:
                req = kwargs['req']
            else:
                req = args[1]

            if req.environ['wsgiorg.routing_args'][1]:
                if _schema_validation_helper(query_params_schema,
                                        req.environ['wsgiorg.routing_args'][1],
                                        args, kwargs, is_body=False):
                    _remove_unexpected_query_parameters(query_params_schema,
                                                         req)
            else:
                if _schema_validation_helper(query_params_schema,
                                            req.GET.dict_of_lists(),
                                            args, kwargs, is_body=False):
                    _remove_unexpected_query_parameters(query_params_schema,
                                                         req)
            return func(*args, **kwargs)
        return wrapper

    return add_validator