batch – How to combine all videos and subtitles with the same file name

I have a folder that contains different types of subtitles and videos, with each set of videos and subtitles with the same file name, and some videos without subtitles. For example,

video01.mp4

video01.srt

video02.mkv

video02.srt

video03.mp4

video03.sub and .idx

video04.mkv

video05.mkv

video05.sub and .idx

video06.mp4

video06.srt

video06.sub and .idx

and so. The previous example uses only two types of videos (mp4 and mkv) and subtitles (srt and sub / idx). Note that video06 has two types of subtitles (srt and sub / idx) while video04 does not have subtitles.

Is it possible to create a batch file that goes to the folder and mkvmerge any type of video (mkv or mp4 in this case) with any available subtitle (in this case, srt, sub / idx, or both), and send to mkv what will be written in another folder? Given the previous example,

video01.mp4 and video01.srt will be merged using mkvmerge and the output, video01.mkv, will be written to a new folder

Hopefully, I can add other types of video (such as avi) to the code if necessary.