Image order in draw_matches

I am trying to visualize my matches using the draw_matches() function.
However, I noticed, that this function is very picky with the order of the images and the keypoints. If the order is not the exact same one from the matcher, it crashes with an error like this:

OpenCV(4.10.0) /usr/src/debug/opencv/opencv/modules/features2d/src/draw.cpp:241: error: (-215:Assertion failed) i1 >= 0 && i1 < static_cast<int>(keypoints1.size()) in function 'drawMatches' (code: StsAssert, -215)

However, since I work with specific regions of keypoints, I would like to change the order of the images before (its not always the same, to ensure that the matchlines are drawn logically, with the shortest distance, and not all accross the image. Is this possible?

This is my code, in the case that the image order differs from the order in the matcher, otherwise it works fine.

To clarify:
In my case the images have names like 1.jpg 2.jpg 3.jpg etc.

pub fn export_visualization_raw_matches(
    img1: &ImageInfo,
    img2: &ImageInfo,
    direction: Direction,
    matches: Vector<DMatch>,
) -> anyhow::Result<()> {
    // Extract numbers from filenames
    let num1: u32 = img1.filename().replace(".jpg", "").parse()?;
    let num2: u32 = img2.filename().replace(".jpg", "").parse()?;

    // Determine left and right images
    let (left_img, left_dir, right_img, right_dir) = if num1 < num2 {
        (img1, direction, img2, direction.inverse())
    } else {
        (img2, direction.inverse(), img1, direction)
    };

    let mut outimg = Mat::default();
    let _ = draw_matches(
        &left_img.image(),
        left_img.get_keypoints(&left_dir).unwrap(),
        &right_img.image(),
        right_img.get_keypoints(&right_dir).unwrap(),
        &matches,
        &mut outimg,
        Scalar::all(-1.0),
        Scalar::all(-1.0),
        &Vector::new(),
        DrawMatchesFlags::DRAW_RICH_KEYPOINTS,
    )
    .context("Failed to draw matches")?;

    let output_filename = format!(
        "matches_raw_img{}_img{}.jpg",
        left_img.filename().replace(".jpg", "").as_str(),
        right_img.filename().replace(".jpg", "").as_str(),
    );

    // Save the output image
    imwrite(&output_filename, &outimg, &Vector::new())?;
    println!(
        "Raw matches visualization of image {} <-> image {} saved.",
        left_img.filename().replace(".jpg", "").as_str(),
        right_img.filename().replace(".jpg", "").as_str(),
    );
    Ok(())
}

How can I modify the order of the images (which one is left/right)?