rewrite rule generated with mpdf to a shorter version

ok it was easy, the problem was that to match the left side pattern you have to use $1 not $matches[1], this is the solution

/**
 * Rewrite rules
 */
add_action( 'init',  function() {
    add_rewrite_rule( '^invoice_([0-9]+).pdf$', '/wp-content/themes/mysitetheme/invoices/invoice_$1.pdf', 'top' );
} );

UPDATE

From the suggestions received in the comments, it is now clear to me that it is not convenient to use rewrite rules for pages inserted in the wordpress folder without being part of the wordpress core itself, so the suitable solution is to generate virtual pages through the use of add_query_var and include a virtual template to be called when this new query variable is requested through index.php. So the correct code is this:

// Here I define my new query var and the related rewrite rules    
add_action( 'init', 'virtual_pages_rewrite', 99 );
    function virtual_pages_rewrite() {
        global $wp;
        $wp->add_query_var( 'invoice' );
        add_rewrite_rule( '^invoice_([0-9]+).pdf$', 'index.php?invoice=$matches[1]', 'top' );
    }

    // This part is just to prevent slashes at the end of the url
    add_filter( 'redirect_canonical', 'virtual_pages_prevent_slash' );
    function virtual_pages_prevent_slash( $redirect ) {
        if ( get_query_var( 'invoice' ) ) {
            return false;
        } return $redirect;
    }
    // Here I call my content when the new query var is called
    add_action( 'template_include', 'virtual_pages_content');
    function virtual_pages_content( $template ) {
        $fattura = get_query_var( 'fattura' );
        if ( !empty( $fattura) ) {
            include get_template_directory().'/includes/mpdf/invoice.php';
            die;
        }
        return $template;
    }