using non-read-only static variables in extremely bad programming practice. It means that you will get very weird bugs or even program crashes if you try to call this function from different threads. Please, get rid of all such variables and pass them as function parameters