Noise removal from images

I get indexing error while executing defining the function

how to fix the issue?