Custom page with queries returns 404

WordPress rewrites standard wordpress urls from /category/post-name/ or whatever your selected permalink type is, into index.php?….

You are adding query vars to a link that is already getting rewritten into index.php?… and thus you are getting a 404.

My advice to you would be to use something similar to an already asked question at Custom page template query_vars or register the query vars properly in WordPress.

WordPress developer reference for adding a query argument -> https://developer.wordpress.org/reference/functions/add_query_arg/

I believe that this should answer your question about how you can handle this.