Hello.
Sorry for the delay; I did some testing here.
It appears that you did not change the values from their defaults as I suggested, so I would not expect the code you posted to make the sensor results behave any differently than if those lines were omitted.
ST does not provide especially clear documentation of how those variables affect measurements, but I did not see a clear pattern here in my test configuration (using the sensor at a distance of about 160mm with a large white board), so perhaps they will not be very useful for your application, either. However, increasing Measurement Timing Budget seems like a reliable way to decrease variation of measurements. Here are standard deviations of a set of 250 single measurement samples using different measurement timing budgets.
As you can see, increasing the length of time of the measurements reliably decreases the variance of the measurements, however you are trading measurement time for accuracy in those situations. Averaging multiple measurements should also decrease the variance. In my somewhat ideal test setup (with a large, close, reflective object), it appears that (if the trend holds), it would take several seconds of averaging to get to 0.5mm repeatability reliably. I would expect a non-ideal situation to take longer,
-Nathan
