Transfer parameter-value from loop to function

I note that you still have more than one variable named matchtime, each with their own scope, one of which is global, and you have mangled the end of your code