Check function depth for parsing object indices

Closes PR 14509