The code borders on being indeciperable.
Do not use global variables. See Passing Extra Parameters for the correct way to pass information to functions.
I have no idea what you’re doing or what you want the code to do. If you want to compare individual rows or columns, see the documentation section on Matrix Indexing to understand how to select them. It is then straightforward to loop through the matrices.