Check if variable is set in filter

The variable you have named $query is actually the WP_Query instance having filters applied to it.

You can simply call its function get to retrieve query vars.

For example:

function votes( $where, $query )
{
    $sort = $query->get('sort');
    if (!empty($sort)
        $where .= " AND $sort >= votes";
    return $where;
}

404 Not Found

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.