Jesus was attempting to hide the fact that he was the Messiah. But, it's not because he was afraid of the local authority. Rather, he was trying to delay the events of his death. He knew that the timing had to be perfect and these events recorded in Matthew were "too soon".
Part 1: The secret
In John 7, Jesus' disciples are going up to the festival. Jesus, however, did not want to appear publicly:
John 7:6 (NIV)
Therefore Jesus told them, “My time is not yet here; for you any time will do.
Later, it says, he decides to go in secret:
John 7:10 (NIV)
However, after his brothers had left for the festival, he went also, not publicly, but in secret.
This theme plays out multiple times. The idea that seems pretty clear is that Jesus is trying delay the timing of these events. (This is clear in the phrasing "My time is not yet here".)
Part 2: The revealing
Later, we see that Jesus says the time has come:
John 12:23 (NIV)
Jesus replied, "The hour has come for the Son of Man to be glorified."
If we read this entire section (John 12:20-36), we see that Jesus is saying that the time has come from him to be crucified. Indeed, directly after this, he says
John 12:24 (NIV)
Very truly I tell you, unless a kernel of wheat falls to the ground and dies, it remains only a single seed. But if it dies, it produces many seeds.
After this (during the same event), Jesus says:
John 12:27 (NIV)
Now my soul is troubled, and what shall I say? ‘Father, save me from this hour’? No, it was for this very reason I came to this hour.
He's clearly speaking of the crucifixion and the suffering that he must endure. These were the events that it seems he was attempting to delay
Part 3: The completion
John records the final words of Jesus:
John 19:30 (NIV)
When he had received the drink, Jesus said, “It is finished.” With that, he bowed his head and gave up his spirit.
We see here the theme that has played out through the entire gospel of John. Jesus wanted to delay the events of the crucifixion and suffering until the time has come. Once the events were in place, Jesus declares that the hour has come. After the crucifixion was complete and his life was over, the events that were the purpose of his life (John 12:27 (NIV) above) are complete. This was the time that Jesus was referring to.
Jesus was clearly (and understandably) troubled by the thought of his own crucifixion and death (John 12:27 (NIV) above). However, the reason that he was hiding and delaying the events wasn't out of fear, but because he knew the correct timing and knew that it shouldn't begin too early.
Therefore, Jesus tried to delay some of the early events in order to make sure the timing was correct and perfect. This includes hiding the fact that he was the Messiah.