Initialise index to 0 since the algorithm seems to depend on it

Modelica Spec says the usage of uninitalised function variables is tool-dependent. In OpenModelica you get whatever is on the stack. Dymola probably initialises it to 0.