Because the function receives the data via a parameter and also operates on that data via an external variable, it is difficult to keep track of what the function is doing.
EDIT (March 29, 2021):
@michaelberge, if you can provide us with that code, we would be in a better position to understand the relationship between the function and the data, and to diagnose the problem.