in which way idioms are metaphoric? what is the function they fulfil in speech?
A metaphor is when you directly compare thing A to thing B by saing that A is B. If you say "A is like B", then that's not a metaphor, but a simile. The phrase "As dead as a doornail" is a type of idiom, but it is not a metaphor, because you are saying that someone or something is similar to a doornail. But the idiom "He's a Greek god" is also a metaphor, because he (if we are referring to a human being) is not really a god -- Greek or otherwise. That idiom means that he looks rather like some of the paintings of Greek gods -- handsome, muscular, etc.
Very often, "idiom" is just the way we say things. For example, it's perfectly grammatically correct to say, "I don't understand the humour in that joke", but nobody would ever say that; it's more idiomatic to say, "I don't get it."
Similes and metaphors add colour and imagination to our speech (unless, of course, they are used so often that they become clichés) -- they make language more interesting. If, as a foreigner, you are able to use idiomatic speech, you will sound less foreign, more natural.